from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField,TextAreaField,SelectField,HiddenField,DateTimeField,BooleanField
from wtforms.validators import DataRequired,Email

class LoginForm(FlaskForm):
    username = StringField('用户名', validators=[DataRequired()])
    email = StringField('邮箱', validators=[DataRequired(), Email()])  # 添加的邮箱字段
    password = PasswordField('密码', validators=[DataRequired()])
    submit = SubmitField('登录')

class BaseDocumentForm(FlaskForm):
    document_id = HiddenField('文档ID')
    title = StringField('标题', validators=[DataRequired()])
    content = TextAreaField('内容', validators=[DataRequired()])
    author_name = StringField('作者', validators=[DataRequired()])
    drafting_unit = StringField('发文单位', validators=[DataRequired()])
    receiving_unit = StringField('接受单位', validators=[DataRequired()])
    status = StringField('状态', validators=[DataRequired()])
    security_level = SelectField('安全级别', choices=[('无', '无'), ('秘密', '秘密'), ('机密', '机密'), ('绝密', '绝密')])
    modified_date = StringField('修改时间')

class DocumentAddForm(BaseDocumentForm):
    action = SelectField('操作', choices=[('save_draft', '保存草稿'), ('submit_review', '提交审核')])
    submit = SubmitField('确认')

class DocumentEditForm(BaseDocumentForm):
    action = SelectField('操作', choices=[('save_draft', '保存草稿'), ('submit_review', '提交审核')])
    submit = SubmitField('确认')

class DocumentAuditForm(BaseDocumentForm):
    audit_result = SelectField('审核结果', choices=[('通过', '通过'), ('不通过', '不通过')])
    submit = SubmitField('确认审核')

class PublicDocumentForm(FlaskForm):
    """
    公共公文表单类，对应public_documents表结构
    """
    title = StringField('标题', render_kw={"readonly": True})
    drafting_unit = StringField('发文单位', render_kw={"readonly": True})
    receiving_unit = StringField('收文单位', render_kw={"readonly": True})
    encrypted_sm4_key = StringField('加密SM4密钥（hex格式）', render_kw={"type": "hidden"})  # 设置为隐藏字段
    sm4_iv = StringField('SM4初始向量', render_kw={"type": "hidden"})  # 设置为隐藏字段
    content = TextAreaField('公文内容', render_kw={"readonly": True})  # 使用TextAreaField来展示多行文本内容，并设置为只读，用于显示解密后的公文内容
    sm3_signature = StringField('SM3哈希签名值', render_kw={"type": "hidden", "readonly": True})  # 新增的签名值字段，设置为隐藏且只读
    is_verified = BooleanField('是否验证成功', render_kw={"readonly": True})  # 新增的是否验证成功字段，设置为只读
    status = SelectField('状态', choices=[('待签收', '待签收'), ('已查看', '已查看'), ('已签收', '已签收'), ('签收失败', '签收失败')], render_kw={"disabled": True})  # 通过disabled实现只读效果
    upload_time = DateTimeField('上传时间', format='%Y-%m-%d %H:%M:%S', render_kw={"readonly": True})
    receive_time = DateTimeField('接受时间', format='%Y-%m-%d %H:%M:%S', render_kw={"readonly": True})



